<?php
/**
 * Created by JetBrains PhpStorm.
 * User: wouterrombaut
 * Date: 9/05/11
 * Time: 10:40
 * To change this template use File | Settings | File Templates.
 */
 
class RegistrationForm extends sfForm {

  public function configure()
  {


    $this->setWidgets(array(
      'firstname' => new sfWidgetFormInputText(array(), array('placeholder' => 'Enter your first name')),
      'lastname' => new sfWidgetFormInputText(array(), array('placeholder' => 'Enter your last name')),
      'email' => new sfWidgetFormInputText(array(), array('placeholder' => 'Enter you email')),
      'email2' => new sfWidgetFormInputText(array(), array('placeholder' => 'Repeat your email')),
      'password' => new sfWidgetFormInputPassword(array(), array('placeholder' => 'Enter your password')),
      'password2' => new sfWidgetFormInputPassword(array(), array('placeholder' => 'Repeat your password')),
      'birth_date' => new sfWidgetFormDate(),
      'sex' => new sfWidgetFormChoice(array('choices' => array('M', 'V'))),
      'phone' => new sfWidgetFormInputText(array(), array('placeholder' => 'Enter your phone number(eg. +3216112233')),
      'mobile' => new sfWidgetFormInputText(array(), array('placeholder' => 'Enter your mobile number(eg. +32499235689'))
    ));

    $this->getWidgetSchema()->setNameFormat('register[%s]');

    $this->setValidators(array(
      'firstname' => new sfValidatorString(array('required' => true), array('required' => 'First name is a required field.', 'invalid' => 'First name cannot contain numbers')),
      'lastname' => new sfValidatorString(array('required' => true), array('required' => 'Last name is a required field.', 'invalid' => 'Last name cannot contain numbers')),
      'email' => new sfValidatorEmail(array('required' => true), array('required' => 'Email is a required field.', 'invalid' => 'Invalid email format inserted.')),
      'email2' => new sfValidatorEmail(array('required' => false)),
      'password' => new sfValidatorRegex(array('required' => true, 'pattern' => "^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$"), array('required' => 'Password is a required field.', 'invalid' => 'Password is not strong enough.')),
      'password2' => new sfValidatorRegex(array('required' => false, 'pattern' => "^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$")),
      'birth_date' => new sfValidatorDate(array('required' => true), array('required' => 'Birthdate is a required field.')),
      'sex' => new sfValidatorChoice(array('required' => true, 'choices' => array('M', 'V')), array('required' => 'Sex is a required field.')),
      'phone' => new sfValidatorString(array('required' => true), array('required' => 'Phone is a required field.', 'invalid' => 'Phone number does not match the required format.')),
      'mobile' => new sfValidatorString(array('required' => true), array('required' => 'Mobile is a required field.', 'invalid' => 'Mobile number does not match the required format.'))
    ));

    $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'password2', array(), array('required' => 'You must repeat your password.', 'invalid' => 'Passwords don\'t match.')));
    $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('email', '==', 'email2', array(), array('required' => 'You must repeat your email.', 'invalid' => 'Email addresses do not match.')));
    
  }

}
